/**
 * Ingenius-Group S.A.S
 *
 * Project: SAU
 * File: AssignedInstrument.java
 * Date: 13/11/2010
 */

package com.ingenius.sau.shared.model.instruments;

import java.util.Date;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.NotPersistent;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.ingenius.sau.shared.model.core.BaseBean;
import com.ingenius.sau.shared.model.core.Indicator2Evaluate;

/**
 * Class <strong>AssignedInstrument</strong>
 * 
 * @author Jesus David
 * @version 0.1
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class AssignedInstrument implements BaseBean {

	// CONSTANTS
	public static final String TYPE_DOCUMENT = "Document";

	public static final String TYPE_QUESTION = "Question";

	// DATA
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
	private String id;

	@Persistent
	private Date createdDate;

	@Persistent
	private double score;

	@Persistent
	private Indicator2Evaluate indicator2Evaluate;

	@Persistent
	private String instrumentType;

	@Persistent
	private String instrumentId;

	@Persistent
	private String groupId;

	@NotPersistent
	private String instrumentDisplay;

	// CONSTRUCTORS

	public AssignedInstrument() {
	}

	public AssignedInstrument(String id) {
		this.id = id;
	}

	// METHODS

	public String getId() {
		return id;
	}

	public Date getCreatedDate() {
		return createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	public double getScore() {
		return score;
	}

	public void setScore(double score) {
		this.score = score;
	}

	public Indicator2Evaluate getIndicator2Evaluate() {
		return indicator2Evaluate;
	}

	public void setIndicator2Evaluate(Indicator2Evaluate indicator2Evaluate) {
		this.indicator2Evaluate = indicator2Evaluate;
	}

	public String getInstrumentType() {
		return instrumentType;
	}

	public void setInstrumentType(String instrumentType) {
		if (TYPE_DOCUMENT.equals(instrumentType)
				|| TYPE_QUESTION.equals(instrumentType)) {

			this.instrumentType = instrumentType;
		}
	}

	public String getInstrumentId() {
		return instrumentId;
	}

	public void setInstrumentId(String instrumentId) {
		this.instrumentId = instrumentId;
	}

	public String getGroupId() {
		return groupId;
	}

	public void setGroupId(String groupId) {
		this.groupId = groupId;
	}

	public String getInstrumentDisplay() {
		return instrumentDisplay;
	}

	public void setInstrumentDisplay(String instrumentDisplay) {
		this.instrumentDisplay = instrumentDisplay;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof AssignedInstrument) {
			return ((AssignedInstrument) obj).getId().equals(id);
		}
		return false;
	}

	@Override
	public String toString() {
		return instrumentType + " - " + instrumentId;
	}

	@Override
	public AssignedInstrument toDTO() {
		return this;
	}

}
